#ifndef HTTPCLIENT_H
#define HTTPCLIENT_H

#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QUrl>
#include <QNetworkReply>
#include <QObject>
#include <QDebug>
#include <QThread>
#include <QSslError>
#include <QPixmap>

class HttpClient : public QObject
{
    Q_OBJECT
public:
    HttpClient();
    ~HttpClient();

    enum HttpType{Get,Post,ByteArray,Image};

    QString GetString(QString url);
    QString PostString(QString url,QString data);
    QNetworkReply* GetByteArray(QString url);
    QNetworkReply* DownloadImage(QString,QString);


    void GetStringAsync(QUrl url);
    void GetByteArrayAsync(QUrl url);
    void GetImageAsync(QUrl url, QString fileName);

private:
    HttpType currentType;   //当前http操作类型
    static const int TIMEOUT = 30000; //超时
    QNetworkAccessManager *qnam;
    QNetworkRequest request;
    QString tag;    //存放其他信息

signals:
    void GetStringFinished(QString);
    void GetByteArrayFinished(QNetworkReply*);
    void GetImageFinished(QNetworkReply *,QString);
    void PostFinished(QNetworkReply *);
    void SslError(QNetworkReply*,QList<QSslError>);
    void HttpTypeError(HttpType type);

private slots:
    void OnGetFinished(QNetworkReply*);
//    void OnGetStringFinished(QNetworkReply*);
//    void OnDownloadImageFinished(QUrl);
    void OnSslErrors(QNetworkReply*,QList<QSslError>);
};

#endif // HTTPCLIENT_H
